package cn.com.shaom.learning.sb.web.web;

import cn.com.shaom.learning.sb.web.bean.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: ThymeleafController
 * Description:
 * Date: 2017/12/22 10:30 【需求编号】
 *
 * @author Shaom
 * @version V1.0.0
 */
@Controller
public class ThymeleafController {

    /**
     * 简单首页
     *
     * @param modelMap
     * @return
     */
    @RequestMapping("index")
    public String index(ModelMap modelMap) {
        Person sam = new Person("sam", 30);
        Person lee = new Person("lee", 30);

        List<Person> personList = new ArrayList<>(2);
        personList.add(sam);
        personList.add(lee);

        modelMap.addAttribute("title", "springboot-web-thymeleaf");
        modelMap.addAttribute("personList", personList);

        return "index";

    }

    /**
     * 访问模板 layout
     *
     * @param modelMap
     * @return
     */
    @RequestMapping("template")
    public String template(ModelMap modelMap) {
        return "template";

    }
}
